package com.cz.fra.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cz.fra.dao.LocationDao;
import com.cz.fra.dao.impl.JdbcLocationDao;

public class RetrieveLocationsServlet extends HttpServlet{

	 /**
	 * Generated serialVersionUID
	 */
	private static final long serialVersionUID = 9162383129363421474L;
	
	LocationDao locationDao = new JdbcLocationDao();
	
	public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
		List<String> locationList = locationDao.getLocations();
		response.setContentType("text/plain");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		StringBuffer sb = new StringBuffer();
		for(String s : locationList){
			sb.append(s.trim());
			sb.append(";");
		}
		out.write(sb.toString());
		out.flush();
		out.close();
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
		doGet(request,response);
	}

}
